<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>


        const persons = [
            {
                name: 'yuzelin',
                score: 99,
                students: [
                    {
                        name: 'fangyunchuan',
                        score: 100,
                    },
                    {
                        name: 'zenghonggui',
                        score: 120,
                    },
                    {
                        name: 'junge',
                        score: 190,
                        students: [
                            {
                                name: 'chenwen',
                                score: 220,
                            },
                            {
                                name: 'zhongge',
                                score: 110,
                            },
                        ],
                    },
                ],
            },
            {
                name: 'zhangzhihao',
                score: 210,
                students: [],
            },
        ];

        // 1. 打印所有的名字
        function logNames (arr = []) {
            for (const item of arr) {
                console.log(item.name);
                logNames(item.students);
            }
        }

        logNames(persons);

        // 2. 求分数之和
        let sum = 0;
        function addScore (arr = []) {
            for (const item of arr) {
                sum += item.score;
                addScore(item.students);
            }
        }

        addScore(persons);


    </script>
</body>
</html>